Chris Pollett >Old Classes >
CS151

( Print View )

Student Corner:
  [Grades Sec5]

  [Submit Sec5]

  [Email List Sec5]

  [
Lecture Notes]

Course Info:
  [Texts & Links]
  [Topics]
  [Grading]
  [HW Info]
  [Exam Info]
  [Regrades]
  [Honesty]
  [Additional Policies]
  [Announcements]

HW Assignments:
  [Hw1]  [Hw2]  [Hw3]
  [Hw4]  [Hw5]

Practice Exams:
  [Mid1]  [Mid2]  [Final]

                           












HW#5 --- last modified March 02 2019 21:22:56..

Solution set.

Due date: Dec 7

Files to be submitted:
  Hw5.zip

Purpose: To gain familarity with various design patterns, threads and socket programming.

Specification: For HW5 you will create a two programs, a TicTacToeClient application and a TicTacToeServer application. You will submit these programs in the file Hw5.zip. To build your programs the grader will unzip this file and type:

ant
java TicTacToeServer
java TicTacToeClient
java TicTacToeClient

Your TicTacToeServer should create a JFrame which looks something like:

TicTacToeServer

Port to bind to: [     ]

Active Games:

+---------------------+
|                     |
|                     |
|                     |
+---------------------+

[Restart Server]

When the Restart Server JButton is clicked the server should notify any connected players that the server is going down, close any existing connections, and kill off any associated threads. It should then create a ServerSocket bound to the port number given in the text field of this GUI. The TicTacToeClient GUI looks roughly like:

TicTacToeClient
---------------------------------
Help
---------------------------------
Host: [                     ] [Go] 
Games Available:
+----------------+
|                |
|                |   [Join]
|                |
+----------------+
[        ][New Game]

Someone using the TicTacToeClient can type in a URL and click Go. This makes a connection to the server requesting a list of games that so far only have one player. This connection should then persists until the user closes the application at which point the server should be notified and the connection should be closed. The server's GUI lists all active games in a JTextArea but adds a '+' symbol in front of games with only one player so far. If the URL the client supplied is good, the server should respond to the client request for one player games with a list of one player games. If the URL is bad an alert dialog should appear. These one player games should then be listed in a JList under the Games available JLabel. Selecting one of these games and clicking Join would then start game play. Alternatively, a player can type a new name for a game in the text field next to the New Game button and then click this button. This should send a message to the server to create a new game with that name that somebody else could join. This should give an error message if a game with that name already exists at the server. The client who creates the game gets to go first in the tic-tac-toe game that ensues and the client who joins gets to go second. The Help menu should have two menu items: Instructions and About TicTacToe, which should pop up information dialogs with instructions or information about you the programmer of the tic-tac-toe game respectively.

Once a game has begun the TicTacToeClient JFrame should change to look something like:

TicTacToeClient
---------------------------------
View Help
---------------------------------

   |    |
   |    |
---+----+---
   |    |
   |    |
---+----+---
   |    |
   |    |


[Quit Game]

Clicking Quit while the game is not over should notify the server that the player no longer wishes to play. The server should notify the other player that he has won by forfeit. The program should then go back to the first screen above to select start or join a game. The Help menu should be the same as before. The View should list three different themes with which to display the tic-tac-toe board. You should make use of a prototype pattern for setting themes. The server should notify a client when the other player moves and should send an updated board. If it is the player's turn and he clicks on a unoccupied position then those coordinates should be sent to the server and the server should send back to both players the new board. The server should send an error message for illegal moves or moving out of turns and these should generate some message that a player will see or hear. The server should also detect if someone wins or if the game is a draw. In this case, after notifying the players, the server should remove this game from this list of active games. On the clients, a win or draw notification should be displayed. A player can then click the Quit button to go back to the start screen to play another game.

Point Breakdown

Departmental coding guidelines for Java followed 1pt
Server GUI as described 1pt
Server Active Games List and Restart button works as described 1pt
Server can handle up to five simultaneous games 1pt
Server handles interactions with clients as described 1pt
Client first screen GUI as described 1pt
Client second screen GUI as described 1pt
Client menus and alerts work described 1pt
Prototype pattern used for theming 1pt
Can use clients as described above to play game 1pt
Total10pts